# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html
from scrapy.exceptions import DropItem
import pymongo
import pymysql

class SavePipeline:
    def __init__(self):
        self.client = pymongo.MongoClient(host="127.0.0.1", port=27017)
        self.database = self.client["spider"]
        self.col = self.database["LianjiaData"]

    def process_item(self, item, spider):
        try:
            self.col.insert_one(item)
        except Exception as e:
            spider.logger.warning(e)
        return item
